package com.fishingwithme.infrastructure;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class CodeEnumSerializer extends JsonSerializer<CodeEnum> {
    @Override
    public void serialize(CodeEnum value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (value == null) {
            gen.writeNull();
            return;
        }

        gen.writeStartObject();
        gen.writeStringField("code", value.getClass().cast(value).name()); // 枚举名称
        gen.writeNumberField("type", value.getType()); // 类型编码
        gen.writeStringField("name", value.getName()); // 类型名称
        gen.writeEndObject();
    }
}